/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.gzchengguo.cn
* 注意：
* 本软件为www.gzchengguo.cn开发研制，未经购买不得商用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package link.chengguo.orangemall.message.rocketmq;

import link.chengguo.orangemall.enums.OrderInfoEnum;
import link.chengguo.orangemall.modules.order.domain.OrangeStoreOrder;
import link.chengguo.orangemall.modules.order.service.OrangeStoreOrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQListener;

/**
 * @ClassName 消费者
 * @Author chengguo <1256747612@qq.com>
 * @Date 2020/1/1
 **/
//@Component
//@RocketMQMessageListener(
//        topic = "orangemall-topic",
//        consumerGroup = "orangemall-group",
//        selectorExpression = "*"
//)
@Slf4j
@AllArgsConstructor
public class MqConsumer implements RocketMQListener<String> {

    private final OrangeStoreOrderService storeOrderService;

    @Override
    public void onMessage(String msg) {
        log.info("系统开始处理延时任务---订单超时未付款---订单id:" + msg);

        Long id = Long.valueOf(msg);

        OrangeStoreOrder order = storeOrderService.lambdaQuery()
                .eq(OrangeStoreOrder::getId, id)
                .eq(OrangeStoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_0.getValue())
                .one();

        //只有待支付的订单能取消
        if(order != null){
            storeOrderService.cancelOrder(order.getOrderId(),null);
            log.info("订单id:{},未在规定时间支付取消成功",id);
        }

        log.info("=====处理成功======");

    }
}
